﻿@model NineSeas.Models.BookPart
@{
    Style.Require("jQueryUI_Orchard");
    Style.Require("NineSeas.Common");
    Style.Require("NineSeas.Reader");
    Style.Require("NineSeas.Authoring");
    Style.Require("NineSeas.Authoring.Book.Edit");

    Script.Require("jQuery").AtHead();
    Script.Require("jQueryUI");
    Script.Require("NineSeas.Common");
    Script.Require("NineSeas.InplaceMessage");
    Script.Require("NineSeas.Authoring.Book.Edit");
    Script.Require("NineSeas.MediaUploadButton");
    Script.Require("FriendUrl");
    Script.Require("TinyMce");
    Script.Require("TagsAutocomplete");

    var imageUrl = String.IsNullOrWhiteSpace(Model.ImageUrl) ?
                                Url.Content("~/Modules/NineSeas/Images/placeholder-book.png")
                                : Model.ImageUrl;
}
<fieldset id="edit-area">
    <div class="authoring-edit-image authoring-book-image" id="imageArea">
        <img src="@imageUrl" alt="@Model.Name"/>
        @T("Click to change")
    </div>        
    <div class="nineseas-field-label">@T("Name")</div>
    <div class="nineseas-field-input">
        @Html.TextBoxFor(x => x.Name)
    </div>
    <div class="nineseas-field-label">@T("Name On Url")</div>
    <div class="nineseas-field-input">
        @Html.TextBoxFor(x => x.NameOnUrl)
    </div>
    <div style="clear:both;"></div>        
    <div class="nineseas-field-label">@T("Introduction")</div>
    <div class="nineseas-field-input">
        @Html.TextAreaFor(m => m.Introduction, 25, 80, new Dictionary<string,object> {
		            {"class", "html tinymce"},
                    {"style", "width:100%; height: 350px"}
	                })
    </div>
    <div style="clear:both"></div>       
    @Html.HiddenFor(x => x.ImageStoragePath, new {@id = "imageStoragePath" })
</fieldset>
@using (Script.Foot()) {
<script type="text/javascript">
    //<![CDATA[
    $(function () {
        var updateEditorHeight = function() {
            var newHeight = $('#nineseas-reader-content').height() - 300;
            if (newHeight < 300) newHeight = 300;

            if ($('#txtIntroduction_ifr').length > 0) {
                $('#txtIntroduction_ifr').height(newHeight);
            } else {
                    
                $('#txtIntroduction').height(newHeight + 20);
            }
        };

        $('#nineseas-reader-content').bind("heightChanged", updateEditorHeight);

        var token = "@Html.AntiForgeryTokenValueOrchard()";
        
        $('#imageArea').mediaUploadButton({
            'action': '@Url.Action("BookImage", "Upload", new { Area = "NineSeas"})',
                'mediaName': 'BookImage',
                data: {
                    '__RequestVerificationToken': token
                },
                callback: function (result) {
                    if (result.success && result.filePath) {
                        $('#imageArea img').attr('src', result.publicUrl);
                        $('#imageStoragePath').val(result.filePath);
                    } else if (result.message) {
                        $.inplaceMessage({
                            type: "error",
                            messageTitle: "@T("Error:")",
                            messageContent: result.message
                        });
                    }
                }
        });
    });
    //]]>
</script>
}